﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml.Serialization;
using System.ComponentModel;

namespace BDSim
{
    /// <summary>
    /// 地面段
    /// </summary>
    public class GroundSegment : SegmentBase
    {
        #region 字段

        /// <summary>
        /// 获取各星座系统地面段信息
        /// </summary>
        ObservableCollection<SubGroundSegment> _SubGroundSegmentList = new ObservableCollection<SubGroundSegment>();
        private GroundDataProvider _DataProvider = new GroundDataProvider();

        public string directotyname;

        /// <summary>
        /// 地面段数据交互模型类
        /// </summary>
        [XmlIgnore, Browsable(false)]
        public GroundDataProvider DataProvider
        {
            get { return _DataProvider; }
            set { _DataProvider = value; }
        }

        #endregion

        #region 属性

        /// <summary>
        /// 获取各星座系统地面段信息
        /// </summary>
        [Browsable(false)]
        public ObservableCollection<SubGroundSegment> SubGroundSegmentList
        {
            get { return _SubGroundSegmentList; }
            set { _SubGroundSegmentList = value;}
        }

        #endregion

        public GroundSegment()
        {
            DefineCommand();
            Menu.ItemsSource = MenuCommandList;

            _DataProvider.Parent = this;
            _DataProvider.DefineCommand();
            Menu.ItemsSource = _DataProvider.MenuCommandList;
        }

        #region 初始化
        public override void Init()
        {
            //创建保存数据文件路径及文件            
            string defaultpath = Directory.GetCurrentDirectory() + "\\DataRecords\\地面段\\";
            DateTime NowTime = DateTime.Now;
            string NowTimeString = NowTime.Year.ToString() + string.Format("{0:D2}", NowTime.Month) + string.Format("{0:D2}", NowTime.Day) +
                "_" + string.Format("{0:D2}", NowTime.Hour) + "_" + string.Format("{0:D2}", NowTime.Minute) + "_" + string.Format("{0:D2}", NowTime.Second);
            directotyname = defaultpath + "自定义数据_" + NowTimeString;
            if (!Directory.Exists(directotyname))
            {
                Directory.CreateDirectory(directotyname);
            }

            base.Init();
            //给_SubGroundSegmentList每一个对象（item）赋值
            foreach (var item in _SubGroundSegmentList)
            {
                item.Parent = this;
            }
            foreach (var item in SubGroundSegmentList)
            {
                item.Init();
            }
        }
        #endregion

        #region 单步运行
        public override void StepRun()
        {
            base.StepRun();
            foreach (var item in SubGroundSegmentList)
            {
                item.StepRun();
            }
        }
        #endregion

        #region 右键命令
        List<MenuCommand> MenuCommandList = new List<MenuCommand>();

        //新建伪卫星命令
        MenuCommand AddPseudolite = new MenuCommand();

        //地面段命令
        public void DefineCommand()
        {

          //  AddPseudolite.Header = "新建伪卫星";
           // AddPseudolite.DefineExcuteCommand(AddPseudoliteFun);
           // MenuCommandList.Add(AddPseudolite);
        }

        void AddPseudoliteFun(object param)
        {
           // Pseudolite pseudolite = new Pseudolite();
          //  pseudolite.Name = "伪卫星";

          //  SubGroundSegmentList.Add(pseudolite);
        }

        #endregion 右键命令

        internal void AddSubGroundSegment(SubGroundSegment subGroundSegment)
        {
            subGroundSegment.Parent = this;
            SubGroundSegmentList.Add(subGroundSegment);
        }
    }
}
